home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9874 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: solon.com!not-for-mail
  2. From: tanmoy@qcd.Lanl.GOV (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Re: Integral promotion problem
  5. Date: 13 Mar 1996 20:25:18 -0600
  6. Organization: Los Alamos National Laboratory
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4i802e$45r@solutions.solon.com>
  10. References: <31404525.26295649@dub-news-svc-3.compuserve.com>
  11.     <314405dd.13127805@dub-news-svc-3.compuserve.com>
  12. NNTP-Posting-Host: solutions.solon.com
  13.  
  14. In article <4i6foi$p2p@solutions.solon.com>
  15. johnb@pivotal-dm.ccmail.compuserve.com (John Bain) writes:
  16.  
  17. <snip>
  18. JB: I.e. (assuming a is unsigned short) in evaluating ~a, a is first
  19. JB: promoted to int (well defined), the int value is converted to unsigned
  20. JB: int (well defined), ~ is applied to the unsigned value (well defined),
  21. JB: and the unsigned result is converted back to int (implementation
  22. JB: defined, if, as seems likely, the value of the unsigned int result
  23. JB: cannot be represented in an int.)
  24.  
  25. No. I can't find any evidence for the int-->unsigned-->int
  26. conversion. (If anyone can find it in the standard, please correct
  27. me.)  Actually the standard states the following:
  28.  
  29. 1) a is promoted.
  30. 2) The bits of the int value are complemented
  31. 3) The value represented by the above bit pattern depends on the
  32.    implementation. 
  33.  
  34. On a two's complement machine where changing from unsigned --> int
  35. does not involve change in bit pattern, your sequence gives the same
  36. result. In general it does not.
  37.  
  38. Thus, for example, given any int x, if no two bit patterns represent
  39. the value ~x, ~~x is guaranteed equal to x. The expression
  40. (int)~(unsigned)(int)~(unsigned)x however is implementation defined;
  41. and therefore not known to equal x in general.
  42.  
  43. Note that the standard does not gurantee that for unsigned y,
  44. (unsigned)(int) y == y even when the representation of the value
  45. (int)y is unique.
  46.  
  47. Cheers
  48. Tanmoy
  49. --
  50. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  51. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  52. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  53. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  54. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  55. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  56.